package com.buaa.controller;

import com.buaa.model.request.PaperRequest;
import com.buaa.model.solr.Paper;
import com.buaa.service.PaperService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jca.cci.core.InteractionCallback;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by DELL on 2018/3/20.
 */
@Controller
@RequestMapping("/paper")
public class PaperController {

    @Autowired
    PaperService paperService;

    @ApiOperation(value="获取论文列表",httpMethod = "POST", response = Paper.class, notes="根据 机构、作者 查询论文",consumes = "application/json")
    @RequestMapping(value = "/findPaperListByAuthorAndOrg",method = RequestMethod.POST,consumes = "application/json")
    @ResponseBody
    public Object findPaperListByAuthor(@RequestBody PaperRequest paperRequest){

        List<Paper> paperList = new ArrayList<>();
        String author = paperRequest.getAuthor();
        String organization = paperRequest.getOrganization();
        int begin = paperRequest.getBegin();
        int size = paperRequest.getSize();

        if(begin == 0 && size ==0){
            size = 10;
        }


        if(organization == null || organization.equals("")){
            paperList = paperService.findPaperListByAuthor(author,begin,size);
        }else{
            paperList = paperService.findPaperListByAuthorAndOrg(author,organization,begin,size);
        }
        return paperList;
    }


    @ApiOperation(value="获取论文列表",httpMethod = "POST", response = Paper.class, notes="根据 关键字 查询论文",consumes = "application/json")
    @RequestMapping(value = "/findPaperListByKeyword",method = RequestMethod.POST,consumes = "application/json")
    @ResponseBody
    public Object findPaperListByKeyword(@RequestBody PaperRequest paperRequest){

        List<Paper> paperList = new ArrayList<>();
        String keyword = paperRequest.getAuthor();
        int begin = paperRequest.getBegin();
        int size = paperRequest.getSize();

        paperService.findPaperListByKeyword(keyword,begin,size);

        return paperList;
    }


}
